package org.carshared.principal;

import java.util.ArrayList;

import org.carshared.R;
import org.carshared.utils.PassengerBeen;
import org.carshared.utils.TravelBeen;

import com.google.gson.Gson;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class NewTravelPassengerActivity extends Activity {

	private EditText precioT;
	private EditText origenDestino;
	private TravelBeen dataTravel;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_newtravel_passenger);
		dataTravel = new TravelBeen();
		precioT = (EditText) findViewById(R.id.precioTray);
		origenDestino = (EditText) findViewById(R.id.origenDestino);
	}

	public void saveData(View view) {

		dataTravel.setPrecioTrayecto(Float.parseFloat(precioT.getText()
				.toString()));
		dataTravel.setOrigenDestino(origenDestino.getText().toString());
		dataTravel.setTipo("passenger");
		PassengerBeen p = new PassengerBeen(dataTravel.getOrigenDestino(), "Yo");
		ArrayList<PassengerBeen> listaPasajeros = new ArrayList<PassengerBeen>();
		listaPasajeros.add(p);
		dataTravel.setListaPasajeros(listaPasajeros);
		Intent returnIntent = new Intent();
		Gson gson = new Gson();
		returnIntent.putExtra("result", gson.toJson(dataTravel));
		returnIntent.putExtra("executed", true);
		setResult(RESULT_OK, returnIntent);
		NewTravelPassengerActivity.this.finish();
	}

	public void cancelData(View view) {
		Intent returnIntent = new Intent();
		setResult(RESULT_CANCELED, returnIntent);
		NewTravelPassengerActivity.this.finish();
	}

}
